Questions
18 of 30
1What is the purpose of the transform property in CSS?
2What are the different types of CSS transformations?
3What does transform: translate() do?
4What is the difference between translateX() and translateY()?
5How does rotate() work in CSS?
6What is the unit used in rotation?
7What is the difference between scale() and scaleX(), scaleY()?
8What happens when you use negative values in scale()?
9What does the skew() function do?
10Can you combine multiple transform functions together? How? What is the use of the transform-origin property?
11What is the default transform-origin value?
12How does changing transform-origin affect rotation or scaling?
13What is the difference between translate() and using position or margin for movement?
14What is the difference between 2D and 3D transformations?
15What is the difference between 2D and 3D transformations?
16How do you apply a 3D rotation using CSS?
17How do you apply a 3D rotation using CSS?
18What are perspective and perspective-origin in 3D transforms? What is the purpose of transform-style: preserve-3d?
19What is the use of matrix() in CSS transforms?
20What’s the difference between matrix() and matrix3d()?
21How can you center an element using transform and translate()?
22What is the transition property in CSS used for?
23What are the four main components of a transition?
24What does transition-duration specify?
25What are the common timing function values (e.g., ease, linear, ease-in)?
26What is the shorthand syntax for transition?
27Can multiple CSS properties be transitioned simultaneously? How does transition differ from animation in CSS?
28Can you apply a transition to an element’s pseudo-class (like :hover)?
29Can transitions be triggered by JavaScript?
30What happens if transition-duration is set to 0s?
18 / 30

What are perspective and perspective-origin in 3D transforms? What is the purpose of transform-style: preserve-3d?

Understanding perspective, perspective-origin, and transform-style: preserve-3d in CSS 3D Transforms

In CSS 3D transformations, perspective, perspective-origin, and transform-style: preserve-3d work together to control how depth and 3D positioning appear on screen. They define the viewing distance, the viewpoint position, and how nested elements maintain 3D space.

The perspective property defines how far the viewer is from the Z=0 plane, effectively determining the strength of the 3D effect. A smaller value (e.g., 200px) creates a more intense depth effect, while a larger value (e.g., 1000px) flattens the view.

Example: Applying Perspective

In this example, the parent .scene provides a perspective, making the rotated .box appear as if it’s turning in real 3D space.

The perspective-origin property defines the point from which the viewer observes the 3D scene — similar to moving the camera’s position. By default, it’s at the center (50% 50%), but you can shift it horizontally or vertically.

Example: Changing Perspective Origin

Changing the origin alters how rotations appear. For example, rotating around the Y-axis looks different if the viewer’s perspective is from the left instead of the center.

The transform-style property determines whether child elements of a 3D-transformed element retain their 3D position. Setting transform-style: preserve-3d ensures that child elements are rendered in the same 3D space, maintaining depth and perspective relationships.

Example: Using transform-style: preserve-3d

This property is essential for effects like 3D card flips, where both the front and back faces need to remain in the same 3D plane as the parent element rotates.

Key Points Summary
  1. 1

    perspective — defines the viewer’s distance; smaller values create stronger depth.

  2. 2

    perspective-origin — sets the viewer’s position (like the camera angle).

  3. 3

    transform-style: preserve-3d — allows child elements to maintain their 3D positions.

Best Practices
  1. 1

    Apply perspective to the parent container of 3D elements, not directly on the transforming element.

  2. 2

    Use perspective-origin to control the direction and angle of the 3D view.

  3. 3

    Always use transform-style: preserve-3d when creating nested 3D transformations (like card flips).